{extend name="base"/}
{block name="main"}
<article class="cl pd-20">
<!--<div class="n_tab_line">
		<a href="{:url('goods/supplier')}" class="n_tab_list02">供货商列表</a>
		<a href="{:url('goods/supplier_add')}" class="n_tab_add02">添加供货商</a>
		<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a>
		<div class="cl"></div>
	</div>-->
	
    
    
     <div id="tab_demo" class="HuiTab" style="margin-top: 0px; position: relative;">
                        <div class="tabBar clearfix">
                            <span onclick="window.location.href='{:url('goods/supplier')}'">供货商列表</span>
                            <span class="current" onclick="window.location.href='{:url('goods/supplier_add')}'">添加供货商</span>
                        </div>
                    </div>
	<form action="" method="post" class="form form-horizontal" id="">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>供货商名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="" placeholder="供货商名称" class="input-text" id="supplier_name" name="supplier_name">
				<p class="error">请输入供货商名称</p>
				<p class="error">供货商名称不合法</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系人姓名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="" placeholder="联系人姓名" class="input-text" id="name" name="name">
				<p class="error">请输入联系人姓名</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系人电话：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="" class="input-text" placeholder="联系人电话" id="tel">
				<p class="error">请输入联系人电话</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>联系人地址：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" autocomplete="off" value="" class="input-text" placeholder="联系人地址" id="address">
				<p class="error">请输入联系人地址</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">供货商图片：</label>
			<div class="formControls col-xs-8 col-sm-9">
					<p style="height: 165px;width:165px;border: dashed 1px #e5e5e5">
						<img src="" alt="" id="imgbrand_pic" class="thumbnail">
					</p>
				<div class="upload-btn">
				<span>
					<input name="file_upload" style="display: none" id="uploadImg" type="file" onchange="imgUpload(this);">
					<input type="hidden" value="" id="brand_pic" />
				</span>
					<input class="btn radius btn-secondary" onclick="on_upload()" type="button" value="上传图片">
				</div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">备注：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="" cols="" rows="" id="info" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)"></textarea>
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<input class="btn btn-primary radius" onclick="addSuppAjax()" type="button" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
			</div>
		</div>
	</form>
</article>
{/block}
{block name="script"}
<script src="/public/static/js/ajax_file_upload.js" type="text/javascript"></script>
<script src="/public/static/js/file_upload.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
});
function on_upload() {
	//$("#uploadImg").click();
    $("#uploadImg").trigger("click");
}
//模块输入信息验证
function verify() {
    var supplier_name = $("#supplier_name").val();
    var name = $("#name").val();
    var tel = $("#tel").val();
    var address = $("#address").val();
    var info = $("#info").val();
    if (supplier_name == '') {
        $("#supplier_name").next().show();
        return false;
    } else {
        $(".error").hide();
    }
    pattern= new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>/?~！@#￥……&*（）——|{}【】‘；：”“'。，、？_]");
    if(pattern.test(supplier_name)){
        $("#supplier_name").next().next().show();
        return false;
    }
    if (name == '') {
        $("#name").next().show();
        return false;
    } else {
        $(".error").hide();
    }
    if(tel == ''){
        $("#tel").next().show();
        return false;
    }else{
        $(".error").hide();
    }
    if(address == ''){
        $("#address").next().show();
        return false;
    }else{
        $(".error").hide();
    }
    return true;
}
var flag = false;//防止重复提交
//添加用户
function addSuppAjax() {
    var supplier_name = $("#supplier_name").val();
    var name = $("#name").val();
    var tel = $("#tel").val();
    var address = $("#address").val();
    var info = $("#info").val();
    var logo=$("#brand_pic").val();
    if(verify() && !flag){
        flag = true;
        $.ajax({
            type : "post",
            url : "{:url('goods/supplier_add')}",
            data : {
                'supplier_name' : supplier_name,
                'name' : name,
                'tel' : tel,
                'address' : address,
				'info':info,
				'logo':logo
            },
            success : function(data) {
                if(data['code']>0){
                    layer.msg('添加成功!',{icon:1,time:1000},function () {
                        window.parent.location.href="{:url('goods/supplier')}";
                    });
                }
                else{
                    flag = false;
                    layer.msg(data['message'],{icon:5,time:1000});
                }
            }
        });
    }
}
//供货商图片上传
function imgUpload(event) {
    var fileid = $(event).attr("id");
    var str = $(event).next().attr("id");
    var data = { 'file_path' : "supp/" };
    uploadFile(fileid,data,function(res){
        if(res.code){
            $("#img"+str).attr("src",res.data);
            $("#"+str).val(res.data);
            layer.msg(res.message,{icon:1,time:1000});
        }else{
            layer.msg(res.message,{icon:1,time:1000});
        }
    });
}
</script>
{/block}